<template>
	<view class="page-container">
		<!-- 页面标题 -->
		<view class="page-header">
			<view class="header-content">
				<view class="header-icon">🍽️</view>
				<view class="header-text">
					<text class="header-title">选择学生</text>
					<text class="header-subtitle">为哪位学生预订餐食？</text>
				</view>
			</view>
		</view>

		<!-- 学生列表 -->
		<view class="student-list-container">
			<template v-if="bindList.length > 0">
				<view class="list-header">
					<up-icon name="list" color="#6FD719" size="16"></up-icon>
					<text class="list-title">已绑定学生 ({{bindList.length}})</text>
				</view>

				<view class="student-grid">
					<view
						class="student-card"
						v-for="(item, index) in bindList"
						:key="item.id"
						@click="handlerEditor(item.id)"
					>
						<view class="card-header">
							<view class="student-avatar">
								<text class="avatar-text">{{item.name.charAt(0)}}</text>
							</view>
							<view class="student-basic-info">
								<text class="student-name">{{item.name}}</text>
								<up-tag
									text="已绑定"
									type="success"
									size="mini"
									bgColor="rgba(111, 215, 25, 0.1)"
									color="#6FD719"
									borderColor="transparent"
								></up-tag>
							</view>
						</view>

						<view class="card-content">
							<view class="info-grid">
								<view class="info-item">
									<up-icon name="bookmark" color="#6FD719" size="12"></up-icon>
									<text class="info-label">学号</text>
									<text class="info-value">{{item.studentId || '----'}}</text>
								</view>
								<view class="info-item">
									<up-icon name="home" color="#4CAF50" size="12"></up-icon>
									<text class="info-label">学校</text>
									<text class="info-value">{{item.schoolName}}</text>
								</view>
								<view class="info-item">
									<up-icon name="grid" color="#FF9800" size="12"></up-icon>
									<text class="info-label">班级</text>
									<text class="info-value">{{item.gradeName}} {{item.classesName}}</text>
								</view>
							</view>
						</view>

						<view class="card-action">
							<view class="action-btn">
								<text class="action-text">点菜</text>
							</view>
						</view>
					</view>
				</view>
			</template>

			<template v-else>
				<view class="empty-container">
					<up-empty
						mode="list"
						text="暂无绑定学生"
						textColor="#999"
						iconColor="#ddd"
					></up-empty>
					<view class="empty-actions">
						<up-button
							type="primary"
							size="default"
							@click="handleAddStudent"
							customStyle="background: linear-gradient(135deg, #6FD719 0%, #5BC016 100%); border: none; border-radius: 20rpx;"
						>
							<up-icon name="plus" color="#fff" size="14" style="margin-right: 8rpx;"></up-icon>
							<text style="color: #fff; font-weight: 500;">添加学生</text>
						</up-button>
					</view>
				</view>
			</template>
		</view>

		<!-- 快速操作 -->
		<view class="quick-actions" v-if="bindList.length > 0">
			<view class="quick-action-item" @click="handleAddStudent">
				<up-icon name="plus-circle" color="#6FD719" size="20"></up-icon>
				<text class="quick-action-text">添加学生</text>
			</view>
			<view class="quick-action-item" @click="handleViewHistory">
				<up-icon name="clock" color="#4CAF50" size="20"></up-icon>
				<text class="quick-action-text">预约历史</text>
			</view>
		</view>
	</view>
</template>

<script setup>
	import {
		onMounted,
		ref
	} from 'vue';
	import {
		onShow
	} from '@dcloudio/uni-app'
	import {
		bindStudent
	} from '../../api/student.js';

	const bindList = ref([])

	onShow(async () => {
		const userInfo = uni.getStorageSync("userInfo")
		bindList.value = await bindStudent(userInfo.id);
	})



	const handlerEditor = (id) => {
		uni.navigateTo({
			url: '/pages/selectCombo/selectCombo?id=' + id,
		})
	}

	// 添加学生
	const handleAddStudent = () => {
		uni.navigateTo({
			url: '/pages/createStudent/createStudent'
		})
	}

	// 查看预约历史
	const handleViewHistory = () => {
		uni.navigateTo({
			url: '/pages/userReserve/userReserve'
		})
	}
</script>

<style lang="scss" scoped>
	.page-container {
		background: linear-gradient(180deg, #F8FAFB 0%, #FFFFFF 100%);
		min-height: 100vh;
		padding-bottom: 40rpx;
	}

	/* 页面标题 */
	.page-header {
		background: linear-gradient(135deg, #6FD719 0%, #5BC016 100%);
		padding: 60rpx 30rpx 40rpx;
		border-radius: 0 0 40rpx 40rpx;
		box-shadow: 0 4px 20px rgba(111, 215, 25, 0.2);
		position: relative;
		overflow: hidden;
	}

	.page-header::before {
		content: '';
		position: absolute;
		top: 0;
		left: 0;
		right: 0;
		bottom: 0;
		background: linear-gradient(45deg, rgba(255, 255, 255, 0.1) 0%, transparent 100%);
		pointer-events: none;
	}

	.header-content {
		display: flex;
		align-items: center;
		gap: 20rpx;
	}

	.header-icon {
		font-size: 48rpx;
		width: 80rpx;
		height: 80rpx;
		background: rgba(255, 255, 255, 0.2);
		border-radius: 50%;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.header-text {
		flex: 1;
	}

	.header-title {
		display: block;
		font-size: 36rpx;
		font-weight: 600;
		color: #FFFFFF;
		margin-bottom: 8rpx;
	}

	.header-subtitle {
		font-size: 26rpx;
		color: rgba(255, 255, 255, 0.8);
	}

	/* 学生列表容器 */
	.student-list-container {
		padding: 40rpx 30rpx;
	}

	.list-header {
		display: flex;
		align-items: center;
		gap: 12rpx;
		margin-bottom: 30rpx;
	}

	.list-title {
		font-size: 30rpx;
		font-weight: 600;
		color: #333;
	}

	/* 学生网格 */
	.student-grid {
		display: grid;
		grid-template-columns: 1fr;
		gap: 20rpx;
	}

	.student-card {
		background: linear-gradient(135deg, #FFFFFF 0%, #FAFBFC 100%);
		border-radius: 25rpx;
		padding: 30rpx;
		box-shadow: 0 4px 16px rgba(0, 0, 0, 0.04);
		border: 1px solid rgba(255, 255, 255, 0.8);
		transition: all 0.3s ease;
		position: relative;
		overflow: hidden;

		&:active {
			transform: scale(0.98);
			box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
		}

		&::before {
			content: '';
			position: absolute;
			top: 0;
			left: 0;
			width: 6rpx;
			height: 100%;
			background: linear-gradient(180deg, #6FD719 0%, #5BC016 100%);
		}
	}

	.card-header {
		display: flex;
		align-items: center;
		margin-bottom: 20rpx;
	}

	.student-avatar {
		width: 80rpx;
		height: 80rpx;
		background: linear-gradient(135deg, #6FD719 0%, #5BC016 100%);
		border-radius: 50%;
		display: flex;
		align-items: center;
		justify-content: center;
		margin-right: 20rpx;
		box-shadow: 0 4px 12px rgba(111, 215, 25, 0.3);
	}

	.avatar-text {
		font-size: 32rpx;
		font-weight: 600;
		color: #FFFFFF;
	}

	.student-basic-info {
		flex: 1;
	}

	.student-name {
		font-size: 32rpx;
		font-weight: 600;
		color: #333;
		margin-bottom: 8rpx;
		display: block;
	}

	.card-content {
		margin-bottom: 20rpx;
	}

	.info-grid {
		display: flex;
		flex-direction: column;
		gap: 12rpx;
	}

	.info-item {
		display: flex;
		align-items: center;
		gap: 8rpx;
		padding: 12rpx 16rpx;
		background: rgba(111, 215, 25, 0.03);
		border-radius: 12rpx;
		border: 1px solid rgba(111, 215, 25, 0.1);
	}

	.info-label {
		font-size: 24rpx;
		color: #666;
		min-width: 60rpx;
	}

	.info-value {
		font-size: 26rpx;
		color: #333;
		font-weight: 500;
		flex: 1;
	}

	.card-action {
		display: flex;
		justify-content: center;
	}

	.action-btn {
		display: flex;
		align-items: center;
		gap: 8rpx;
		padding: 16rpx 32rpx;
		background: linear-gradient(135deg, #6FD719 0%, #5BC016 100%);
		border-radius: 20rpx;
		box-shadow: 0 4px 12px rgba(111, 215, 25, 0.3);
	}

	.action-text {
		font-size: 28rpx;
		color: #FFFFFF;
		font-weight: 600;
	}

	/* 空状态 */
	.empty-container {
		background: linear-gradient(135deg, #FFFFFF 0%, #FAFBFC 100%);
		border-radius: 25rpx;
		padding: 80rpx 30rpx;
		text-align: center;
		box-shadow: 0 4px 16px rgba(0, 0, 0, 0.04);
	}

	.empty-actions {
		margin-top: 30rpx;
	}

	/* 快速操作 */
	.quick-actions {
		position: fixed;
		bottom: 40rpx;
		left: 30rpx;
		right: 30rpx;
		display: flex;
		gap: 20rpx;
		z-index: 100;
	}

	.quick-action-item {
		flex: 1;
		background: linear-gradient(135deg, #FFFFFF 0%, #FAFBFC 100%);
		border-radius: 25rpx;
		padding: 20rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
		gap: 8rpx;
		box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
		border: 1px solid rgba(255, 255, 255, 0.8);
		transition: all 0.3s ease;

		&:active {
			transform: scale(0.95);
			box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
		}
	}

	.quick-action-text {
		font-size: 24rpx;
		color: #333;
		font-weight: 500;
	}

	/* 动画效果 */
	.student-card {
		animation: slideInUp 0.4s ease-out;
	}

	.student-card:nth-child(1) { animation-delay: 0.1s; }
	.student-card:nth-child(2) { animation-delay: 0.2s; }
	.student-card:nth-child(3) { animation-delay: 0.3s; }
	.student-card:nth-child(4) { animation-delay: 0.4s; }

	@keyframes slideInUp {
		from {
			opacity: 0;
			transform: translateY(20rpx);
		}
		to {
			opacity: 1;
			transform: translateY(0);
		}
	}

	/* 响应式设计 */
	@media screen and (min-width: 750rpx) {
		.student-grid {
			grid-template-columns: 1fr 1fr;
		}
	}

	@media screen and (max-width: 750rpx) {
		.student-list-container {
			padding: 30rpx 20rpx 120rpx;
		}

		.quick-actions {
			left: 20rpx;
			right: 20rpx;
		}
	}
</style>